<template>
	<view>
		<u-action-sheet :list="sheetList" v-model="moreShow" @click="sheetFun"></u-action-sheet>
		<u-select v-model="allotShow" mode="single-column" confirm-text="确认分配" cancel-text="取消分配" :list="userList"
			@confirm="allotConfirmFun" value-name="_id" label-name="nickname"></u-select>
		<view class="card">
			<view class="topRow1" @click="gotoDetailFun(item)">
				<view class="name">
					<text>{{item.bus_type_name || '暂无'}}</text>
				</view>
				<view v-if="item.bus_name">
					<text class="colorGray">消息内容：</text>
					<text>{{item.bus_name}}</text>
				</view>
				<view v-if="item.deal_time">
					<text class="colorGray">处理时间：</text>
					<text>{{item.deal_time}}</text>
				</view>
			</view>

			<view v-if="!isSelect" class="bottomRow">
				<view class="lxRow">

				</view>
				<view class="lxRow" @click.stop="moreShowFun">
					<image src="/static/icon/gengduosz.png" mode="aspectFill"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		apiSysMsg
	} from '@/api/admin.js'
	import {
		uidUserApi
	} from '@/api/admin.js'
	export default {
		props: {
			item: {
				type: Object,
				default: () => {}
			},
			isSelect: {
				type: Boolean,
				default: false
			},
			index: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				sheetList: [{
						text: '添加跟进'
					},
					{
						text: '编辑'
					},
					{
						text: '删除'
					}
				],
				moreShow: false,
				allotShow: false,
				userList: []
			}
		},
		methods: {
			moreShowFun: function() {
				this.sheetList = [{
						text: '查看详细'
					},
					{
						text: '不在提醒'
					},
					{
						text: '删除'
					}
				];
				this.moreShow = true;
			},
	//跳转到系统消息详情页面
		gotoDetailFun: function(item) {
			// 保存消息信息到全局变量，供详情页使用
			uni.$sysMsgInfo = item;
			console.log('sysMsgInfo');
			uni.navigateTo({
				url: '/pages/admin/sys_msg/detail?index=' + this.index
			})
		},
			sheetFun: function(i) {
				let arr = this.sheetList;
				let str = arr[i].text;
				if (str == '查看详细') {
					this.gotoDetailFun(this.item);
				} else if (str == '不在提醒') {
					this.setDealStatusFun();
				} else if (str == '删除') {
					let that = this;
					uni.showModal({
						title: '提示',
						content: '是否确认删除为：' + that.item.bus_name + '的消息吗?',
						success(res) {
							if (res.confirm) {
								uni.showLoading({
									title: '删除中...',
									mask: true
								})
								let reqData = {
									action: 'del',
									params: {
										req: {
											id: that.item.id
										}
									}
								}
								apiSysMsg(reqData)
									.then(res => {
										uni.showToast({
											title: '删除成功!',
											duration: 1000,
											icon: 'none'
										})
										uni.$emit('deleteKhFun', {
											index: that.index
										})
									})
							}
						}
					})
				}
			},
			// 设置为已经处理
			setDealStatusFun: function() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否确认将消息设置已经处理，处理后不再提醒了?',
					success(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '处理中...',
								mask: true
							})
							let reqData = {
								action: 'set_deal',
								params: {
									req: {
										id: that.item.id
									}
								}
							}
							console.log(reqData);
							apiSysMsg(reqData)
								.then(res => {
									uni.showToast({
										title: '更新成功！',
										duration: 1600,
										icon: 'none',
										mask: true
									});
									uni.$emit('deleteKhFun', {
										index: that.index
									})
								})
						}
					}
				})
			},
		}
	}
</script>

<style>
	.card {

		padding: 26rpx 26rpx 10rpx;
		margin: 32rpx 26rpx;
		box-sizing: border-box;
		border-radius: 16rpx;
		box-shadow: #d8d8d8 0px 0px 16rpx;
		position: relative;
		background-color: #FFFFFF;
	}

	.genjinBtn {
		position: absolute;
		right: 26rpx;
		top: 26rpx;
		background-color: #007AFF;
		color: #FFFFFF;
		text-align: center;
		padding: 6rpx 16rpx;
		border-radius: 6rpx;
		font-size: 14px;
	}

	.genjinBtn:active {
		background-color: #13B8FF;
	}

	.topRow1 {
		margin-bottom: 16rpx;
		font-size: 15px;
		color: #000;
		position: relative;
		line-height: 180%;
	}

	.name {
		font-size: 16px;
		margin-bottom: 8rpx;
		color: #000000;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		font-weight: bold;
	}

	.bottomRow {
		width: 100%;
		padding-top: 16rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-top: 1rpx solid #f0f0f0;
		font-size: 15px;
		color: #007AFF;
	}

	.lxRow {
		display: flex;
		align-items: center;
	}

	.lxRow>image {
		width: 52rpx;
		height: 52rpx;
		margin-right: 26rpx;
	}

	.bqRow {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
	}

	.bqRow>text {
		font-size: 14px;
		color: #888888;
	}

	.bqRow>view {
		padding: 6rpx 16rpx;
		font-size: 14px;
		background-color: rgba(255, 85, 127, 0.1);
		color: #ff5500;
		border-radius: 10rpx;
		margin: 6rpx 26rpx 20rpx 0;
	}

	.khJieDuan {
		position: absolute;
		right: 0;
		top: 50rpx;
		font-weight: bold;
	}

	.khType {
		position: absolute;
		right: 0;
		top: 72rpx;
		font-weight: bold;
	}
</style>
